package com.dupengcheng.subject.domain.hanler.subject;

import com.dupengcheng.subject.common.enums.SubjectTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class SubjectTypeHandlerFactory implements InitializingBean {



    @Resource
    private List<SubjectTypeHandler> handlerList;


    private  Map<SubjectTypeEnum, SubjectTypeHandler> handlerMap=new HashMap<>();

    public  SubjectTypeHandler getHandler(Integer SubjectType){
        SubjectTypeEnum byCode = SubjectTypeEnum.getByCode(SubjectType);
        return handlerMap.get(byCode);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        for (SubjectTypeHandler subjectTypeHandler : handlerList) {
            SubjectTypeEnum subjectTypeEnum = subjectTypeHandler.getSubjectTypeEnum();
            handlerMap.put(subjectTypeEnum,subjectTypeHandler);
        }

    }
}
